#include<bits/stdc++.h>
using namespace std;
#define N 100005
int a[N],d[N],v[N];
int p[N];
set<int> s;
vector<int> who;
bool have[N];
int n,m,L,V;
int ans = N;
void init(){
    ans = N;
    memset(a,0,sizeof(a));
    memset(d,0,sizeof(d));
    memset(v,0,sizeof(v));
    memset(p,0,sizeof(p));
    s.clear();
    who.clear();
}
void dfs(int now = 0){
    if (now == m){
        int res = 0;
        for (int i = 1;i <= m;i++) res += have[i];
        for (int k = 0;k < who.size();k++){
            int i = who[k];
        //    cout << i << endl;
            bool flag = false;
            for (int j = 1;j <= m;j++){
                if (have[j]){
                    if (p[j] < d[i]) continue;
                    double nv = sqrt(v[i] * v[i] * 1.0 + 2.0 * a[i] * (p[j] - d[i]));
                    if (nv > V * 1.0){
                        flag = true;
                        break;
                    }
                }
            }
            if (!flag) return ;
        }
    //    cout << res << endl;
        ans = min(ans,res);
        return;
    }
    dfs(now + 1);
    have[now + 1] = 1;
    dfs(now + 1);
    have[now + 1] = 0;
}
void solve(){
    init();
    cin >> n >> m >> L >> V;
    bool A,B,C;
    A = B = C = true;
    for (int i = 1;i <= n;i++){
        cin >> d[i] >> v[i] >> a[i];
        if (a[i] != 0) A = false;
        if (a[i] > 0) C = false;
        if (a[i] < 0) B = false;
    }
    for (int i = 1;i <= m;i++){
        cin >> p[i];
    }
    int cnt = 0;
    int mx = -1,mn = p[1];
    for (int i = 1;i <= m;i++){
        mx = max(mx,p[i]);
        mn = min(mn,p[i]);
    }
    if (A){
        for (int i = 1;i <= n;i++){
            if (d[i] <= mx && v[i] > V) cnt++;
        }
        cout << cnt << ' ' << m - 1 << endl;
    } else if (B){
        for (int i = 1;i <= n;i++){
            if (d[i] > mx) continue;
            double nv = sqrt(v[i] * v[i] * 1.0 + 2.0 * a[i] * 1.0 * (mx - d[i]));
            if (nv > V * 1.0) cnt++;
        }
        cout << cnt << ' ' << m - 1 << endl;
    } else if (C){
        for (int i = 1;i <= n;i++){
            if (v[i] < V) continue;
            else {
                int pos = lower_bound(p + 1,p + m + 1,d[i]) - p;
                double nv = sqrt(v[i] * v[i] * 1.0 + 2.0 * a[i] * (p[pos] - d[i]));
                s.insert(pos);
                if (nv > 1.0 * V) cnt++;
            }
        }
        cout << cnt << ' ' << m - s.size() << endl;
    } else {
        for (int i = 1;i <= n;i++){
            for (int j = 1;j <= m;j++){
                if (p[j] < d[i]) continue;
                double nv = sqrt(v[i] * v[i] * 1.0 + 2.0 * a[i] * (p[j] - d[i]));
                if (nv > V * 1.0){
                    who.push_back(i);
                    cnt++;
                    break;
                }
            }
        }
        cout << cnt << ' ';
        dfs();
        cout << m - ans << endl;
    }
}
signed main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    int t;
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
